#define  _CRT_SECURE_NO_WARNINGS

/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/
#include <vector>
#include <queue>
using namespace std;

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        queue<Node*> q;
        q.push(root);
        vector<vector<int>> ret;
        if (!root) return ret;
        while (!q.empty())
        {
            int n = q.size();
            vector<int> tmp;
            while (n--)
            {
                Node* node = q.front();
                q.pop();
                tmp.push_back(node->val);
                for (auto& e : node->children)
                    q.push(e);
            }
            ret.push_back(tmp);
        }
        return ret;
    }
};